﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jumpton.SFA.Server.BusinessRule;
using Jumpton.SFA.Server.Entity;
using Jumpton.SFA.Server.BusinessRule.MasterData;
using Jumpton.SFA.Server.BusinessRule.System;

public partial class masterdata_Distributors : PageBase
{

    #region 变量定义
    private const string NEW_PAGE = "Distributor_Maintain.aspx";
    private const string SUCCESS = "操作成功！";
    private const string ERROR = "操作失败！";
    private ChainManager _ChainManager = null;  //经销商操作类
    private int _ChainID = -1;                  //经销商ID号
    private CHAINS _CHAINS = null;              //一个经销商对象
    private DataTable _ChainTable = null;       //经销商列表
  
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {

        //获取经销商ID号
        int.TryParse(Request.QueryString["Did"], out _ChainID);
        if (!IsPostBack)
        {
            DataBind();
            try
            {

                if (_ChainID > 0)
                {
                    _ChainManager = new ChainManager();
                    _CHAINS = _ChainManager.Load(_ChainID);
                }

                if (this.txtHidOrg.Value == "")
                {
                    string[] temp=OrgHidValue.Split(',');
                    if (temp.Length > 0)
                    {
                        this.txtHidOrg.Value = temp[0];
                        this.txtOrg.Text = OrgShowValue;
                    }
                    
                }

            }
            catch { }
        }
       

    }

  

    #region 绑定经销商所涵盖的所有省份
    //private void BindProvince()
    //{
    //    Common.BindDataWithListControl(ddlProvinceList, new DistributorManager().GetProvince(), "Province", "");
    //    ddlProvinceList.Items.Insert(0, "所有");
    //}
    #endregion

    /// <summary>
    /// 查询
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        try
        {

            _ChainManager = new ChainManager();

            _ChainTable = _ChainManager.GetChainTable1(MyStateManager.DomainID,txtHidOrg.Value.Replace("'",""), txtChain.Text, ddlValid.SelectedValue);
            GridPager1.DataSource= _ChainTable;
            GridPager1.GridView = gvChainList;
            GridPager1.BindData();
            GridPager1.Visible = gvChainList.Rows.Count > 0;
        }
        catch { }
    }
    /// <summary>
    /// 新增
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnNewBanner_Click(object sender, EventArgs e)
    {
        Response.Redirect(NEW_PAGE);
       
    }

    
   

    #region 绑定经销商类型
    //private void BindDistributorType()
    //{
    //    _DIM = new DictionaryItemsManager();
    //    //经销商类型
    //    Common.BindDataWithListControl(ddlClass, _DIM.GetItemList(DictionaryEnum.DistributorType, this.MyStateManager.DomainID), "Name", "DictionaryItemId");
    //    ddlClass.Items.Insert(0, new ListItem(Resources.language.ddl_Select, ""));
    //}
    #endregion

    #region 绑定可用区域
    //private void BindDomain(int distributorID)
    //{
    //    _DistributorManager = new DistributorManager();
    //    //绑定域
    //    Common.BindDataWithListControl(ddlDomain, _DistributorManager.GetDomainListOutOfDIS(distributorID), "SYS_NAME", "ID");
    //    ddlDomain.Items.Insert(0, new ListItem(Resources.language.ddl_Select, ""));
    //}
    #endregion

    protected void gvDistributorsList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //控制样式
            Grid_RowDataBound(sender, e);
        }
    }
    /// <summary>
    /// 返回
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnCancel_Click(object sender, EventArgs e)
    {
      
        btnQuery_Click(sender, e);
    }

   
    protected void txtOrg_TextChanged(object sender, EventArgs e)
    {
       
    }
    protected void gvChainList_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvChainList.PageIndex = e.NewPageIndex;
        btnQuery_Click(sender, e);
    }
}
